from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey, JSON
from sqlalchemy.orm import relationship
from datetime import datetime
from database import Base

class FlightRoute(Base):
    __tablename__ = "flight_routes"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), unique=True, index=True, nullable=False)
    description = Column(String(255))
    waypoints = Column(JSON, nullable=False)  # 存储航点信息，格式为[{lat, lng, alt}, ...]
    distance = Column(Float)  # 航线距离（米）
    is_active = Column(Boolean, default=True)  # 1表示激活，0表示未激活
    created_by = Column(Integer, ForeignKey('users.id'))
    created_at = Column(DateTime, default=datetime.now)
    updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
    
    # 关系
    created_user = relationship("User")